#include <bits/stdc++.h>
// 2025/02/02
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m;
int64_t num[10000005];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int64_t l, r, s, e;
        cin >> l >> r >> s >> e;
        num[l] += s;
        num[l + 1] += (e - s) / (r - l) - s;
        num[r + 1] -= e + (e - s) / (r - l), num[r + 2] += e;
    }
    for (int i = 1; i <= n; i++)
        num[i] += num[i - 1];
    int64_t ans = 0, maxn = 0, s = 0;
    for (int i = 1; i <= n; i++){
        s += num[i];
        ans ^= s;
        maxn = max(maxn, s);
    }
    cout << ans << ' ' << maxn;
    return 0;
}